﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Threading;
using System.Globalization;

public partial class Frequency : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
               
                

            }
        }
    }

    protected void edit_Click(object sender, EventArgs e)
    {
        LinkButton lk = (LinkButton)sender;
        ViewState["aoe"] = lk.ToolTip;
        paidfees.Text = ((Label)lk.NamingContainer.FindControl("paidfees")).Text;
        Label vv =(Label)lk.NamingContainer.FindControl("startofsub");
        Label zz = (Label)lk.NamingContainer.FindControl("types");
        numerics.Text = vv.ToolTip;//.Substring(0, 1);
        DropDownList1.SelectedIndex =DropDownList1.Items.IndexOf( DropDownList1.Items.FindByValue(zz.ToolTip));
        Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
    }
    protected void delete_Click(object sender, EventArgs e)
    {
      
        LinkButton lk = (LinkButton)sender;
        string bb = ((Label)lk.NamingContainer.FindControl("paidfees")).ToolTip;
        if (bb == "0")
        {
            DB.DELETE("frequencies", "int,id," + lk.ToolTip);
            GridView1.DataBind();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "alert('لا يمكن المسح حيث انه مرتبط بمنتجات');", true);

        }
    }
    protected void save_Click(object sender, EventArgs e)
    {
        //////////////////////////////////////////////
        List<string> fields = new List<string>();
        ArrayList values = new ArrayList();
        List<string> types = new List<string>();
        ///////////////
       
        /////////////////
        fields.Add("freq");
        types.Add("string");
        values.Add(paidfees.Text);
        /////////////////////////////////////////////////
        fields.Add("nodays");
        types.Add("int");
        values.Add(numerics.Text);
       
        //////////////////////////////////
        /////////////////////////////////////////////////
        fields.Add("type");
        types.Add("string");
        values.Add(DropDownList1.SelectedValue);

        //////////////////////////////////
        try
        {
            if (ViewState["aoe"].ToString() == "0")
            {
                DB.INSERT("frequencies", fields, types, values);
            }
            else
            {
                DB.UPDATE("frequencies", "int,id," + ViewState["aoe"].ToString(), fields, types, values);

            }
            ViewState["aoe"] = 0;
            GridView1.DataBind();

        }
        catch (Exception ex )
        {
            
        }

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lb = (Label)e.Row.FindControl("types");
           // string ss=lb.Text.Substring(0,1);
            switch(lb.Text)
            {
                case "w":
                    lb.Text = "اسبوع";
                    break;
                case "y":
                    lb.Text = "سنة";
                    break;
                case "d":
                    lb.Text =  "يوم";
                    break;
                case "m":
                    lb.Text ="شهر";
                    break;
                default:
                    break;
           // lb.Text = (lb.Text == "020" ? "غير متكرر" : "متكرر");
           
        }

        }
    }
    protected void newsub_Click(object sender, EventArgs e)
    {
        ViewState["aoe"] = 0;
        Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
    }

}
